[#ftl]
<style>
label.error {
    color: Red;
    font-size: 13px;
    margin-left: 5px;
    padding-left: 16px;
}
</style>
<script type="text/javascript" src="${base}/js/form-validate.js"></script>
<script type="text/javascript">   

/*弹出提醒框*/
function tips(param){
       var d=dialog({
                content: param,
                icon: 'succeed',
                fixed: true,
                lock: true,
            });
            d.show();
            setTimeout(function () {
                d.close().remove();
            }, 2000);
            return false;
} 

function changeParent(){
        var selectedId=$("#categoryId").val();
        d=dialog({
            url:'${base}/uyo/platStoreCategory/dataTree?selectedId='+selectedId,  
            title: '选择公司分类',
          //  background: '#EEE', // 背景色
            opacity: 0.05,  // 透明度
            width: 300,
            height: 350
          });   
          d.show();
}
/*清空父类*/
function cleanParent(){
      $("#parentId").val(null); 
      $("#categoryId").val(null); 
      $("#categoryName").val(''); 
}
</script>
</head>
<body>
<!-- 主要内容开始 -->
 <div class="col-md-11">
    <form id="dataform" role="form"  class="form-horizontal"  method="POST">
        <input type="hidden" name="id" id="id" value="${(bean.id)!0}">
        <input type="hidden" name="parentId" id="parentId" value="${(bean.parentId)!}">
        <input type="hidden" name="categoryId" id="categoryId" value="${(bean.parentId)!}">
        <input type="hidden" name="categoryCode" id="categoryCode">
	  <div class="form-group">
	    <label for="type" class="col-sm-2 control-label">类型</label>
	    <div class="col-sm-6">
	      <select class="form-control" name="type" id="type">
             <option value='1' [#if bean.type?exists && bean.type=1]selected="selected"[/#if]>公司</option>
             <option value='2' [#if bean.type?exists && bean.type=2]selected="selected"[/#if]>分店</option>
          </select>
	    </div>
	  </div>
	  <div class="form-group">
	    <label for="categoryName" class="col-sm-2 control-label">上级</label>
	    <div class="col-sm-6">
	       <input type="text" class="form-control" id="categoryName" name="categoryName" value="${(parent.name)!''}"  disabled>
	    </div>
	  </div>
	  <div class="form-group">
	    <label for="ownerId" class="col-sm-2 control-label">所属</label>
	    <div class="col-sm-6">
	      [@c.select id="ownerId" attributes="class='form-control'" value="${bean.ownerId!''}"  datas="store.category.ownerid"/]
	    </div>
	  </div>
	  <div class="form-group">
	    <label for="name" class="col-sm-2 control-label"><span class="red">*</span>名称</label>
	    <div class="col-sm-6">
	      <input type="text" class="required form-control" id="name" value="${bean.name!""}" name="name"/>
	    </div>
	  </div>
	  <div class="form-group">
	    <label for="sequence" class="col-sm-2 control-label">序号</label>
	    <div class="col-sm-6">
	      <input type="text" class="number form-control" id="sequence" name="sequence" value="${(bean.sequence)!""}">
	    </div>
	  </div>
	  <div class="form-group">
	    <label for="status" class="col-sm-2 control-label">状态</label>
	    <div class="col-sm-6">
	      <select id="status" name="status" class="form-control">
		    <option value='0' [#if bean.status?exists && bean.status==0]selected="selected"[/#if]>审核中</option>
            <option value='1' [#if bean.status?exists && bean.status==1]selected="selected"[/#if]>正常</option>
            <option value='2' [#if bean.status?exists && bean.status==2]selected="selected"[/#if]>关闭</option>
          </select>
	    </div>
	  </div>
	  <div class="form-group">
	    <div class="col-sm-offset-2 col-sm-10">
	      <button type="button" class="btn btn-default" id="butSave">保存</button>
	      <button type="button" class="btn btn-default" id="butDelete">删除</button>
	    </div>
	  </div>
    </form>
 </div>
<script type="text/javascript"> 
  $(function() {
        // 保存
        $("#butSave").click(function(){  
            $("#parentId").val( $("#categoryId").val());                        
            $("#dataform").submit();          
         });

        var v = jQuery("#dataform").validate({
             errorElement : "span",  
             errorClass : "help-block",  
             focusInvalid : false,
             submitHandler: function(form) {
                var id=$("#id").val();
                $(form).ajaxSubmit({
                    url:"${base}/uyo/platStoreCategory/"+id+"/update",
                    success: function(data){  
                        noty({
                          text:extendMessages(data).msg.message,
                          layout:"center",
                          timeout:2000,
                          callback:{
                             afterClose:function(){
                                        
                                        }
                           }
                        });
                   }
                });
            },
            highlight : function(element) {  
                $(element).closest('.form-group').addClass('has-error');  
            }, 
            errorPlacement : function(error, element) {  
                element.parent('div').append(error);  
            }
       });
       $("#butDelete").click(function(){
            if (confirm("确定要删除这一项数据吗？")) {
              var id=$("#id").val();
              $.ajax({
                   type : "post",
                   url : "${base}/uyo/platStoreCategory/"+id+"/delete",
                   traditional:true,
                   dataType: "json",
                   success: function(data){ 
                    var messages = extendMessages(data);
                            noty({
                                     text:extendMessages(data).msg.message,
                                      layout:"center",
                                      timeout:2000,
                                      callback:{
                                        afterShow:function(){                                  
                                            if(messages.isAllSuccess())
                                            {
                                                window.location.reload();
                                            }
                                        }
                                      }                          
                           });
                    },
                    error:function(){
                    }
             }); 
          }                   
       });     
  });
</script>
</body>

</html>